/* sinus from 1/4 period (Q15) */
const int SIN_QUARTER[] = {
0x0000, 0x0324, 0x0648, 0x096b, 0x0c8c, 0x0fab, 0x12c8, 0x15e2, 
0x18f9, 0x1c0c, 0x1f1a, 0x2224, 0x2528, 0x2827, 0x2b1f, 0x2e11, 
0x30fc, 0x33df, 0x36ba, 0x398d, 0x3c57, 0x3f17, 0x41ce, 0x447b, 
0x471d, 0x49b4, 0x4c40, 0x4ec0, 0x5134, 0x539b, 0x55f6, 0x5843, 
0x5a82, 0x5cb4, 0x5ed7, 0x60ec, 0x62f2, 0x64e9, 0x66d0, 0x68a7, 
0x6a6e, 0x6c24, 0x6dca, 0x6f5f, 0x70e3, 0x7255, 0x73b6, 0x7505, 
0x7642, 0x776c, 0x7885, 0x798a, 0x7a7d, 0x7b5d, 0x7c2a, 0x7ce4, 
0x7d8a, 0x7e1e, 0x7e9d, 0x7f0a, 0x7f62, 0x7fa7, 0x7fd9, 0x7ff6 };

#define SIN_SIZE sizeof(SIN_QUARTER)

int sinus( int x )
{
	x %= 4*SIN_SIZE;
	if( x < SIN_SIZE ) {
		return SIN_QUARTER[x];
	} else if( x == SIN_SIZE ) {
		return 0x7fff;  // +1 (Q15)
	} else if( x < 2*SIN_SIZE ) {
		x = 2*SIN_SIZE - x;
		return SIN_QUARTER[x];
	} else if( x < 3*SIN_SIZE ) {
		x -= 2*SIN_SIZE;
		return -SIN_QUARTER[x];
	} else if( x == 3*SIN_SIZE ) {
		return 0x8000;	// -1 (Q15)
	} else {
		x = 4*SIN_SIZE - x;
		return -SIN_QUARTER[x];
	}
}

